"""
@author: Leo
@version: 1.0.0
@file: pagination.py
@time: 2023/11/13 11:52 PM
"""
from rest_framework.pagination import PageNumberPagination

from lab.common.response import OK


class CustomPageNumberPagination(PageNumberPagination):
    page_size_query_param = 'page_size'
    max_page_size = 100

    def get_paginated_response(self, data):
        return OK({
            'meta_data': {
                'total_items': self.page.paginator.count,
                'page_size': self.get_page_size(self.request),
                'current_page': self.page.number,
                'total_pages': self.page.paginator.num_pages,
                'next': self.get_next_link(),
                'previous': self.get_previous_link(),
            },
            'results': data
        })
